<!DOCTYPE html>
<html lang="en" xmlns:th=http://www.thymeleaf.org>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=0,maximum-scale=0,user-scalable=yes,shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>表单设计器</title>
    <link rel="stylesheet" href="/admin/component/layui/css/layui.css" />
    <link rel="stylesheet" href="/admin/component/form/modules/cron.css" />
	<link rel="stylesheet" href="/admin/component/form/modules/labelGeneration.css" />
    <link rel="stylesheet" href="/admin/component/form/modules/formDesigner.css" />
</head>

<body class="layui-layout-body">
<!--<button type="button" id="test">aa</button>-->
    <input type="hidden" th:value="${formId}" id="fromId">
    <div style="height: 100%; width: 100%;" id="formdesigner">
        
    </div>
    <script src="/admin/config/config.js"></script>
	<script type="text/javascript" src="/admin/component/layui/layui.js"></script>
    <script type="text/javascript" src="/admin/component/form/js/config.js"></script>
    <script type="text/javascript" src="/admin/component/form/modules/Sortable/Sortable.js"> </script>
    <!--htmlformat 为js-beautify代码-->
    <script type="text/javascript" src="/admin/component/form/js/htmlformat.js"></script>
    <script type="text/javascript" src="/admin/component/form/js/jsformat.js"></script>
    <script type="text/javascript" src="/admin/component/form/modules/iceEditor/iceEditor.js"></script>
    <script>
        layui.config(
		{base: '/admin/component/form/modules/'}).use(['layer', 'formDesigner','form'], function () {
            let formDesigner = layui.formDesigner;
            let data = [],
                req = _req(),
                form = layui.form;
            const setParams = (params, type = 'get') => {
                let str = params.split('|'),
                    keys = str[0].split(','),
                    vals = str[1].split(',');
                keys.forEach((k,i) => {
                    k && addParamsData(k, vals[i],type)
                })
            }
            console.log(req)
            if(req.form_id && req.form_id > 0) {
                _get(layui, 'form/addBefore?id=' + req.form_id, res => {
                //console.log(res)
                    formDesigner.render({
                        data: JSON.parse(res.data),
                        elem:'#formdesigner'
                    });
                    form.val('myform', res);
                    if(res.params_get){
                        setParams(res.params_get, 'get')
                    }
                    if(res.params_post){
                        setParams(res.params_post, 'post')
                    }
                })
                
            }else{
                formDesigner.render({
                    data:data,
                    elem:'#formdesigner'
                });
                form.val('myform', req);
                if(req.params_get){
                    setParams(req.params_get,'get')
                }
                if(req.params_post){
                    setParams(req.params_post,'post')
                }
            }
            //let render = formDesigner.render({
            //    data:data,
            //    elem:'#formdesigner'
            //});

        }); 
    </script>

</body>

</html>